<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>setauth</title>
    <link rel="shortcut icon" href="__STATIC__/favicon.ico">
	  <link href="__STATIC__/role/css/style.css?1.0" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="__STATIC__/xadmin/js/jquery_3.2.1.min.js"></script>
    <script type="text/javascript">
      $(function(){
          var rules = [{$rules['rules']}]; //角色的权限菜单序列数
          $('.auth_rules').each(function(){
              if($.inArray( parseInt(this.value,10),rules)>-1){
                $(this).prop('checked',true);
              }
          });
      });
    </script>
</head>
<body>
<div class="formbody">
  <form action="{:url('role/setauth');}" method="post">
    <input type="hidden" value="{$id}" name='id'/>
    {foreach name="data" item="vo"}
      <div class="topmenu">
        <label>
          <input type="checkbox" value="{$vo.id}" id="chk_{$vo.id}_0_0" name="rules[]" class="auth_rules" onClick="setchecked(this)">
          {$vo.title}</label>
      </div>
      <div class="twomenu">
        {foreach name="vo['two']" item="sub"}
          <p style="padding-bottom:10px;">
            <label>
              <input type="checkbox" value="{$sub['id']}" id="chk_{$vo.id}_{$sub['id']}_0" name="rules[]" class="auth_rules" onClick="setchecked(this)">
              {$sub['title']}</label>
            {foreach name="sub['ree']" item="subr"}
              <label>
                <input type="checkbox" value="{$subr['id']}" name="rules[]" id="chk_{$vo.id}_{$sub['id']}_{$subr['id']}" class="auth_rules" onClick="setchecked(this)">
                <b style="font-weight:normal;">{$subr['title']}</b></label>
            {/foreach}
          </p>
        {/foreach}
      </div>
    {/foreach}
    <input type="submit" class="btn" value="确认"/>
  </form>
</div>
<script type="text/javascript">
function setchecked(obj)
{
  var objId = obj.id;
  var id1 = objId.split("_")[1];
  var id2 = objId.split("_")[2];
  var id3 = objId.split("_")[3];
  var ischk= obj.checked;
  if(id3 != "0"){
    if(ischk){
      document.getElementById("chk_" + id1 + "_" + id2 + "_0").checked = ischk;
      document.getElementById("chk_" + id1 + "_0_0").checked = ischk;
    }
  }else if(id2 != "0"){
    if(ischk){
      document.getElementById("chk_" + id1 + "_0_0").checked = ischk;
    }
    var chks = document.getElementsByTagName("input");
    for(i=0; i<chks.length; i++){
      if(chks[i].id.indexOf("chk_" + id1 + "_" + id2 + "_")!=-1){
        chks[i].checked = ischk;
      }
    }
  }else{
    var chks = document.getElementsByTagName("input");
    for(i=0; i<chks.length; i++){
      if(chks[i].id.indexOf("chk_" + id1 + "_")!=-1){
        chks[i].checked = ischk;
      }
    }
  }
}
</script>
</body>
</html>